package com.qf.dao;
import com.qf.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;
import java.util.List;
//mybatis入门案例
public class Demo01 {
    public static void main(String[] args) throws Exception {
        //1 加载mybatis的核心配置文件
        InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        //2 获取SqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //3 获取SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4 执行指定的statement
        List<User> userList = sqlSession.selectList("test.selectUserList");
        System.out.println(userList);
        //5 关闭会话
        sqlSession.close();
    }
}
